<template>
	<view class="">
		<view class="my-list">
			<u-list :height="swiperHeight" @scrolltolower="scrolltolower" v-if="clientList.length > 0">
				<u-list-item v-for="(item, index) in clientList" :key="index">
					<view class="padding-20 bg-white mt-20" @click="onRadio(item)">
						<text class>{{item.organizationName}}</text>
					</view>
				</u-list-item>
			</u-list>
		</view>
		<!-- 无数据时默认显示 -->
		<view class="emptybox" v-if="clientList.length == 0">
			<u-empty icon-size="150" text="暂无数据" mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
	import listHeightMixin from '@/common/computedAltitude.js'
	export default {
		mixins:[listHeightMixin],
		data(){
			return {
				clientList: [],
				total: 1, // 总页数
				searchData: {
					page: 1,
					limit: 99,
				}
			}
		},
		onLoad() {
			this.GetOrganizationList()
		},
		methods: {
			GetOrganizationList(){
				this.$reqPost('OrganizationGetPageList', this.searchData).then(res=>{
					if(res.count === 0 || res.count <= this.searchData.limit){
						this.total = 1
					}else {
						this.total = res.count%this.searchData.limit==0?(res.count/this.searchData.limit):(Math.floor(res.count/this.searchData.limit)+1);
					}
					this.clientList = [...this.clientList, ...res.data]
				})
			},
			// 选择数据
			onRadio(row){
				let data = {
					organizationId: row.id,
					organizationName: row.organizationName,
				}
				uni.$emit('select-department', data)
				uni.navigateBack()
			},
			scrolltolower(){
				if(this.searchData.page < this.total){
					this.searchData.page ++
					this.GetOrganizationList()
				} else if (this.searchData.page >= this.total){
					return 
				}
			}
		}
	}
</script>
